<?php

namespace App\Http\Controllers\Company\English;

use App\Facades\Style;
use App\Http\Controllers\Company\CommonController;
use App\Models\Common\CollArea;
use App\Models\Common\CollOption;

use App\Models\Common\English\EnCollArea;
use App\Models\Common\English\EnCollOption;
use App\Models\Personal\ResumeSend;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class BrowseCompanyController extends CommonController
{
    /**
     * 谁浏览过我
     * @param Request $request
     * @return mixed
     */
    public function index(Request $request)
    {
        $user = auth()->guard('company')->user();
        //获取面试通知记录
        $relist = DB::table('browse_company as log')
            ->join('resume as t1', 'log.resume_id', '=', 't1.id')
            ->select(
                'log.id', 'log.updated_at', 't1.name', 't1.sex', 't1.birthday',
                't1.education', 't1.homeaddress', 't1.intentionjobs', 't1.jobarea1', 't1.jobarea2', 't1.jobarea3', 't1.jobarea4', 't1.jobarea5','t1.language','log.resume_id'
            )
            ->where('log.company_uid', $user->uid)
            ->where(function ($query) use ($request) {
                if (strlen($request->keyWord) > 0) {
                    $query->where('t1.intentionjobs', 'like', '%' . $request->keyWord . '%')->orWhere('t1.name', 'like', '%' . $request->keyWord . '%');
                }
            })
            ->orderBy('log.updated_at', 'DESC')
            ->paginate(20);
        //print_r($queries );

        foreach ($relist as $v) {
            if ($v->language == 'en') {
                switch ($v->sex) {
                    case "1":
                        $v->cnsex = 'Man';
                        break;
                    case "2":
                        $v->cnsex = 'Woman';
                        break;
                    default:
                        $v->cnsex = '';
                }
                $v->education = EnCollOption::getOptionName($v->education, 'education');
                $v->homeaddress = EnCollArea::getAreaName($v->homeaddress);
                $v->birthday = birthday($v->birthday);
                $v->jobarea = $v->jobarea1 ? EnCollArea::getAreaName($v->jobarea1) : '';
                $v->jobarea .= $v->jobarea2 ? ';' . EnCollArea::getAreaName($v->jobarea2) : '';
                $v->jobarea .= $v->jobarea3 ? ';' . EnCollArea::getAreaName($v->jobarea3) : '';
                $v->jobarea .= $v->jobarea4 ? ';' . EnCollArea::getAreaName($v->jobarea4) : '';
                $v->jobarea .= $v->jobarea5 ? ';' . EnCollArea::getAreaName($v->jobarea5) : '';
            } else {
                switch ($v->sex) {
                    case "1":
                        $v->cnsex = '男';
                        break;
                    case "2":
                        $v->cnsex = '女';
                        break;
                    default:
                        $v->cnsex = '';
                }
                $v->education = CollOption::getOptionName($v->education, 'education');
                $v->homeaddress = CollArea::getAreaName($v->homeaddress);
                $v->birthday = birthday($v->birthday);
                $v->jobarea = $v->jobarea1 ? CollArea::getAreaName($v->jobarea1) : '';
                $v->jobarea .= $v->jobarea2 ? ';' . CollArea::getAreaName($v->jobarea2) : '';
                $v->jobarea .= $v->jobarea3 ? ';' . CollArea::getAreaName($v->jobarea3) : '';
                $v->jobarea .= $v->jobarea4 ? ';' . CollArea::getAreaName($v->jobarea4) : '';
                $v->jobarea .= $v->jobarea5 ? ';' . CollArea::getAreaName($v->jobarea5) : '';
            }
        }
        return Style::view('company.english.browseCompanyIndex', compact('relist'));
    }
}